package com.ll.domain.classbase.base.impl;

import com.ll.dal.mapper.CourseMapper;
import com.ll.app.api.req.PageCourseReqDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ll.base.dto.PageResultDTO;
import com.ll.dal.po.CoursePO;
import com.ll.domain.classbase.base.CourseBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class CourseBaseServiceImpl extends ServiceImpl<CourseMapper, CoursePO> implements CourseBaseService {

    private final CourseMapper courseMapper;

    @Override
    public PageResultDTO<CoursePO> page(PageCourseReqDTO req) {
        req.initPage();
        IPage iPage = new Page(req.getPageNo(), req.getPageSize());
        iPage = courseMapper.selectPage(iPage, new LambdaQueryWrapper<CoursePO>()
                .in(CoursePO::getStatus, req.getStatues())
                .orderByAsc(CoursePO::getStartTime)
        );
        PageResultDTO<CoursePO> pageResult = new PageResultDTO<CoursePO>(iPage.getRecords(), iPage.getTotal(), req);
        return pageResult;
    }

    @Override
    public void apply(Long id) {
        courseMapper.apply(id);
    }

    @Override
    public void cancelApply(Long id) {
        courseMapper.cancelApply(id);
    }

//    @Override
//    public CoursePO getByIdAndStatus(Long id, List<CourseStatusEnum> statusList) {
//        CoursePO coursePO = courseMapper.selectOne(new LambdaQueryWrapper<CoursePO>()
//                .eq(CoursePO::getId, id).in(CoursePO::getStatus, statusList));
//        return null;
//    }

}
